package com.hzhjhh.view.manageView.menus.accountMng.register;

import javax.swing.JButton;
import javax.swing.JOptionPane;

import org.apache.ibatis.session.SqlSession;

import com.hzhjhh.mapper.UserInfoMapper;
import com.hzhjhh.means.DelData;
import com.hzhjhh.util.DBUtils;
import com.hzhjhh.view.manageView.menus.accountMng.RegisterDialog;

/**
 * 菜单栏初始化-仓库-账户管理-添加/修改用户-管理员登录弹出框-删除用户按钮用户弹出框-删除用户按钮
 * 
 * @author 12083
 *
 */
public class DeleteBt {

	private static UserInfoMapper userInfoMapper;
	
	/**
	 * 按钮
	 */
	public static JButton btInit(RegisterDialog registerDialog) {
		JButton delete = new JButton();
		delete.setBounds(75, 279, 83, 25);
		delete.setText("删除用户");

		delete.addActionListener(event -> {
        	int i= userInfoMapper.delete(registerDialog.getTxfCardId().getText());
//            i= DelData.delCard(registerDialog.getTxfCardId().getText());
            if (i != 0) {
                JOptionPane.showMessageDialog(registerDialog, "删除成功", "提示",
                        JOptionPane.INFORMATION_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(registerDialog, "删除失败", "提示",
                        JOptionPane.INFORMATION_MESSAGE);
                return;
            }
        });
		
		// 初始化mapper
		SqlSession sqlSession = DBUtils.getSqlSession(true);
		userInfoMapper = sqlSession.getMapper(UserInfoMapper.class);
		
		return delete;
	}
}
